home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / Utilities / Installer v3.4.3 / Examples - Installer 3.4 / UserFunction Samples / UserFunction Sample / UserFunction.c next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  3.5 KB  |  145 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  *
  3.  *    Apple Macintosh Developer Technical Support
  4.  *
  5.  *  Installer 3.1 sample: User Functions
  6.  *
  7.  *    File:        UserFunction.c -    c Source
  8.  *
  9.  *    by:            Jon Zap
  10.  *  updated for use with Installer 3.4 by: Rich Kubota 9/1/92
  11.  *
  12.  *    Copyright © 1988-1990 Apple Computer, Inc.
  13.  *    All rights reserved.
  14.  *
  15.  *----------------------------------------------------------------------------*/
  16. #if 0
  17. c -b UserFunction.c
  18. Link -ra =resPurgeable -rt infn=1001 -rn -m USERFUNCTION -t rsrc -c RSED ∂
  19.         UserFunction.c.o ∂
  20.         "{Libraries}"Interface.o ∂
  21.         -o UserFunction.rsrc
  22. #endif
  23.  
  24. /* applec is only defined by MPW C so we can use it to make versions that work
  25.   with MPW C and THINK C
  26.  */
  27. #ifdef applec
  28. #include    <CType.h>
  29. #include    <Quickdraw.h>
  30. #include    <Windows.h>
  31. #include    <OSUtils.h>
  32. #include    <desk.h>
  33. #include    <dialogs.h>
  34. #include    <Errors.h>
  35. #include    <Events.h>
  36. #include    <Memory.h>
  37. #include    <Menus.h>
  38. #include    <SegLoad.h>
  39. #include    <Slots.h>
  40. #include    <ToolUtils.h>
  41. #include    <Devices.h>
  42. #include    <Resources.h>
  43. #include    <SysEqu.h>
  44. #endif
  45.  
  46. #include "UserFunction.h"
  47.  
  48. #ifndef applec
  49. #define screenActive scrnActive
  50. #endif
  51.  
  52. #define kTobyBoardID 5
  53.  
  54. Boolean checkBoardID(void);
  55.  
  56. pascal Boolean UserFunction(short targetVRefNum, long blessedID, long whichFunction)
  57. {
  58. #pragma unused (blessedID, targetVRefNum)
  59.  
  60.     switch (whichFunction) {    /* switch is useless here but we assume that we'll add other userFunctions */
  61.     
  62.     case FindMyBoard: 
  63.         return checkBoardID();
  64.     }
  65. }
  66.  
  67. Boolean checkBoardID()
  68. {
  69.     int        Index,i;
  70.     OSErr        err;
  71.     int            slots[6];
  72.     GDHandle    aDev, aDevList[6];
  73.     AuxDCEHandle DCE;
  74.     int            lastDevIndex;
  75.     SInfoRecord    mySInfoRec;
  76.     SpBlock        mySpBlock;
  77.     SysEnvRec theSys;
  78.     short theBoardID;
  79.     
  80.  
  81.     err = SysEnvirons(1,&theSys);            /* should use gestalt (or even better check with a rule before calling this function) */
  82.     if (err!=noErr || !theSys.hasColorQD) {    /* without color QD this thing is irrel */
  83.         return false;
  84.         }
  85.  
  86.     /* go thru the graphics device list and get the list of active screen gdevices
  87.         and the slot numbers of their cards
  88.     */
  89.     for (Index = 0, aDev = GetDeviceList(); aDev; aDev = GetNextDevice(aDev))
  90.         if (TestDeviceAttribute(aDev,screenDevice)&&TestDeviceAttribute(aDev,screenActive))
  91.             {
  92.             aDevList[Index] = aDev;
  93.             lastDevIndex = Index;
  94.             DCE = (AuxDCEHandle) GetDCtlEntry((**aDev).gdRefNum);
  95.             slots[Index] = (**DCE).dCtlSlot; /* get the slot number */
  96.             Index++;
  97.             }
  98.     
  99.     /* go thru each of the devices/cards and see if the board id is MINE */
  100.     for (i=0; i<=lastDevIndex; i++) {
  101.         Index = slots[i];
  102.         /* init parameters for SReadInfo */
  103.         mySpBlock.spResult = (long) &mySInfoRec;
  104.         mySpBlock.spSlot = Index; /* which slot to look at */
  105.         
  106.         /* let's see if any board is in the slot */
  107.         err = SReadInfo (&mySpBlock);
  108.         if (err) {
  109.             /* report error */
  110.             continue;
  111.             }
  112.         
  113.         if (mySInfoRec.siInitStatusA == smEmptySlot) {    /* pretty weird if no card! */
  114.             continue;
  115.             }
  116.  
  117.         /* init parameters for sNextTypesRsrc, look for card info of the following type */
  118.         /* Look in slot (Index) */
  119.         mySpBlock.spSlot = Index;
  120.         mySpBlock.spID = 0;
  121.         mySpBlock.spExtDev = 0;
  122.         mySpBlock.spCategory = 1;
  123.         mySpBlock.spCType = 0;
  124.         mySpBlock.spDrvrSW = 0;
  125.         mySpBlock.spDrvrHW = 0;
  126.         
  127.         err = SNextTypeSRsrc (&mySpBlock);
  128.         
  129.         if (err) {    /* report error */
  130.             continue;
  131.             }
  132.         
  133.         /* init parameters for SReadWord */
  134.         mySpBlock.spID = 32; /* board ID */
  135.         err = SReadWord(&mySpBlock);
  136.         if (err) {    /* report error */
  137.             continue;
  138.             }
  139.         theBoardID = (mySpBlock.spResult & 0x0000FFFF);
  140.         
  141.         if (theBoardID == kTobyBoardID)
  142.             return true;
  143.         }
  144.     return false;
  145. }